package com.syni.mdd.yhd.common.all.quartz.userReceCoupon;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsVideo;
import com.syni.mdd.yhd.common.all.entity.coupon.BmsUserReceCoupon;
import com.syni.mdd.yhd.common.all.service.BmsUserReceCouponService;
import com.syni.mdd.yhd.common.all.service.BmsVideoService;
import com.syni.mdd.yhd.common.all.utils.SpecificationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @className UserReceCoupon
 * @description TOO
 * @Author cfx
 * @DATE 2019/10/31 19:41
 * @VERSION 1.0
 **/
@Component
@EnableScheduling
public class UserReceCouponQuartz {

    @Autowired
    BmsUserReceCouponService bmsUserReceCouponService;

    @Scheduled(cron = "0 0 0/2 * * ?")
    //@Scheduled(cron = "0/5 * * * * ?")
    public void setReceCouponIsExpire(){
        final int expireTip = 2;
        Date nowTime = new Date();
        Map<String,Object> paramsMap = new HashMap<>();
        paramsMap.put("status",Constants.GROUP_NO_USE);
        paramsMap.put("expireTime_LTTE",nowTime);
        List<BmsUserReceCoupon> bmsUserReceCoupons = bmsUserReceCouponService.getBaseDao().findAll(new SpecificationUtils(paramsMap));
        if(bmsUserReceCoupons != null && bmsUserReceCoupons.size() > 0){
            for(BmsUserReceCoupon bmsUserReceCoupon : bmsUserReceCoupons){
                bmsUserReceCoupon.setStatus(expireTip);
            }
            bmsUserReceCouponService.getBaseDao().saveAll(bmsUserReceCoupons);
        }
    }
}
